package com.sx.jys.ui.act

import android.content.Intent
import android.os.Bundle
import com.sanxinsaas.nearstore.framework.util.click
import com.sos.widget.app.dialog.HintDialog
import com.sos.widget.view.helper.FormatJudge
import com.sos.widget.view.helper.InputTextHelper
import com.sx.jys.app.framework.BaseActivity
import com.sx.jys.databinding.ActLoginBinding
import com.sx.jys.ui.vm.LoginVm

class LoginAct : BaseActivity<LoginVm, ActLoginBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        getImmersionBar().titleBar(titleBar).init()
        InputTextHelper.Builder(this)
            .setMain(mDatabind.tvLogin)
            .addView(mDatabind.edLogin)
            .addView(mDatabind.edPassword)
            .setListener {
                return@setListener FormatJudge.isEmpth(it.getmViewSet())
            }
            .build()

    }

    override fun initData() {
        mDatabind.vm = mViewModel
        mDatabind.tvLogin.click {
            mViewModel.reqLogin()
        }
    }

    override fun createObserver() {
        super.createObserver()
        mViewModel.loginSuccessEvent.observe(this) {
            HintDialog.Builder(this)
                .setIcon(HintDialog.ICON_FINISH)
                .setMessage("登录成功!")
                .addOnDismissListener {
                    startActivity(Intent(this@LoginAct, MainAct::class.java))
                    finish()
                }.show()
        }
    }
}